﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;



namespace DatabaseHandler{
    public class ConnectionHandler
    {
        public MySqlConnection BuildConnection(string server, string databaseName, string user, string pass)
       {
           //build the connection string
           string connStr = "server=" + server + ";database=" + databaseName + ";uid=" + user + ";password=" + pass + ";";

           //Convert the string to a MySqlConnection
           MySqlConnection connection = new MySqlConnection(connStr);

           //return the connection string
           return connection;
       }

        public Boolean OpenConnection(MySqlConnection Connection)
        {
            try
            {
                Connection.Open();
                MessageBox.Show("MySQL Connection Succeeded", "Success");
                return true;
            }
            catch (MySqlException ex)
            {
                MessageBox.Show("MySQL Connection Failed! " + ex.Message, "Error");
                MessageBox.Show("Please check the information you filled in");
                return false;
            }
        }

        public void CloseConnection(MySqlConnection Connection){
        Connection.Close();}


       
    }
}